package com.ideaaedi.plugin.fastcoding.action;

import com.ideaaedi.commonds.exception.ExceptionUtil;
import com.ideaaedi.plugin.fastcoding.ui.FastCodingSettings;
import com.ideaaedi.plugin.fastcoding.util.NotifyUtil;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;

/**
 * 设置触发
 *
 * @author JustryDeng
 * @since 2021/12/18 9:10:51
 */
public class SettingsAction extends AnAction {
    
    public static final String ACTION_NAME = "Fast Coding Settings";
    
    @Override
    public void actionPerformed(AnActionEvent event) {
        Project project = event.getData(PlatformDataKeys.PROJECT);
        if (project == null) {
            return;
        }
        try {
            ApplicationManager.getApplication().invokeLater(() -> ShowSettingsUtil.getInstance().showSettingsDialog(project, FastCodingSettings.class), ModalityState.defaultModalityState());
        } catch (Exception e) {
            NotifyUtil.notify(project, ACTION_NAME, ExceptionUtil.getStackTraceMessage(e), NotificationType.ERROR);
        }
    }
}
